<?php
  class media_genre{
    private $template;
    private $util;
    private $db;
   
    public function __construct(){
        require_once 'code/util.class.php';   
        $this->util = new util();
        $this->db = new db();
    }
    
    public function autorun(){
        $act =  isset($_GET['act'])?$_GET['act']:'list_top';  
        switch($act){
            case 'allGenre':
                $this->get_all_genre();
                break;
            case 'list_top':
                $this->list_top(); 
                break;       
            case 'listsong':
                $this->list_song();
                break;
            default:
                $this->list_top(); 
                break;   
            
        }
          
    }
    
    public function list_top(){  
        $sql = "SELECT *  FROM genre ORDER BY name LIMIT 0,10";
        $this->db->openconnection();
        $genre = $this->db->run_query($sql);
        $this->db->closeconnection();
        return $genre;
    } 
    
      //get all genre
    private function get_all_genre(){
        $this->db->openconnection();
        $genre = $this->db->run_select_data('genre','name');
        $this->db->closeconnection();
        
        //Send data to template
        $this->util->send_var('genres', $genre);
        return ($this->util->generate_page('../templates/media-frontend/genre/list_all.tpl'));
    }  
    
  }
?>
